package com.danke.blog.util;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * md5
 *
 * @author hw
 * @create 2018-05-21 14:59
 **/
public class MD5Util {

    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }

    private static final String SALT = "1a2d3c4d";

    public static String inputPassToFormPass(String inputPassword) {
        String str = "" + SALT.charAt(0) + SALT.charAt(2) + inputPassword + SALT.charAt(5) + SALT.charAt(7);
        return md5(str);
    }

    public static String formPassToDBPass(String formPass, String salt) {
        String str = "" + salt.charAt(0) + salt.charAt(2) + formPass + salt.charAt(5) + salt.charAt(7);
        return md5(str);
    }

    public static String inputPassToDBPass(String inputPass, String salt) {
        String formPass = inputPassToFormPass(inputPass);
        return formPassToDBPass(formPass, salt);
    }
}
